package me.leiusual.sharing.ui.mine.adapter

import android.view.View
import androidx.recyclerview.widget.RecyclerView
import kotlinx.android.extensions.LayoutContainer
import kotlinx.android.synthetic.main.view_holder_mine_invited.*
import me.leiusual.sharing.api.model.Invited
import me.leiusual.sharing.util.extension.setImageUrl

/**
 * Create by leiusual on 2018/7/22
 */
class MineInvitedViewHolder(
    override val containerView: View,
    private val clickListener: (Invited.Response.User) -> Unit,
    private val renewClickListener: (Invited.Response.User) -> Unit
) : RecyclerView.ViewHolder(containerView), LayoutContainer, View.OnClickListener {

  private lateinit var user: Invited.Response.User

  init {
    containerView.setOnClickListener(this)
    button_renew.setOnClickListener(this)
  }

  fun bind(data: Invited.Response.User) {
    this.user = data

    image_view_header.setImageUrl(data.avatar)

    text_view_nickname.text = "会员 ${data.username}"

    text_view_auth.text = if (data.realName.isNullOrBlank()) "未实名" else "已实名"
    text_view_auth.isChecked = !data.realName.isNullOrBlank()

    // text_view_online.text = if (data.online) "在线" else "离线"
    // text_view_online.isChecked = data.online

    // text_view_mobile.text = if (data.mobile.isNullOrBlank()) "未绑定手机号" else data.mobile

    text_view_date.text = "创建时间 ${data.createTime}"

    // text_view_login_count.text = "登录${data.loginCount}次"

    text_view_invited_count.text = "已邀请${data.invitedCount}人"

    text_view_store_info.text = data.storeInfo
  }

  override fun onClick(v: View?) {
    when (v) {
      containerView -> clickListener(user)
      button_renew -> renewClickListener(user)
    }
  }
}